﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Yugi.Client.DataModel;
using Yugi.Client.Card;
using Common;

namespace Yugi.Client
{
    public partial class SupervisorModel
    {
        private void ProcessFromServer_CARD_SETCONG(object[] data)
        {
            this.TableGame.Presenter.Do(ClientMSG.ThayDoiCong, data);
        }
        private void ProcessFromServer_CARD_SETTHU(object[] data)
        {
            this.TableGame.Presenter.Do(ClientMSG.ThayDoiThu, data);
            
        }
        //------------------------API-----------------------------//
        private void ProcessFromServer_API_DRAWCARD(object[] data)
        {
            int id=(int)data[0];
            if(id== Nguoi_Choi.YPlayer.ID)
                this.Nguoi_Choi.Presenter.Do(ClientMSG.Api_DrawCard, data);
            else
                this.Doi_Thu.Presenter.Do(ClientMSG.Api_DrawCard, data);
        }
        private void ProcessFromServer_API_SPECIALSUMMON(object[] data)
        {
            this.TableGame.Presenter.Do(ClientMSG.Api_SpecialSummon, data);
        }
        private void ProcessFromServer_API_SPECIALSUMMON_XONG(object[] data)
        {
            this.TableGame.Presenter.Do(ClientMSG.Api_SpecialSummon_DoiThu, data);
        }
        private void ProcessFromServer_API_CHANGECONTROL(object[] data)
        {
            this.TableGame.Presenter.Do(ClientMSG.Api_ChangeControl, data);
        }
        //-------------------------Xoa----------------------
        private void ProcessFromServer_CARD_XOABAI_TAY(object[] data)
        {
            this.Nguoi_Choi.Presenter.Do(ClientMSG.XoaBaiTay, data);
        }
        private void ProcessFromServer_CARD_XOABAI_GRAVEYARD(object[] data)
        {
            int player_id = (int)data[0];
            if (player_id == Nguoi_Choi.YPlayer.ID)
                Mo_Nguoi_Choi.Presenter.Do(ClientMSG.XoaBai, data);
            else if(player_id == Doi_Thu.YPlayer.ID)
                Mo_Doi_Thu.Presenter.Do(ClientMSG.XoaBai, data);
        }
        private void ProcessFromServer_CARD_MOVETO_GRAVEYARD(object[] data)
        {
            int player_id = (int)data[0];
            CardModel temp = new CardModel((YBaseCard)data[1],this);
            if (player_id == Nguoi_Choi.YPlayer.ID)
                //Mo_Nguoi_Choi.Presenter.Do(ClientMSG.ThemBaiVaoMo, temp);
                Mo_Nguoi_Choi.Add(temp);
            else if (player_id == Doi_Thu.YPlayer.ID)
                //Mo_Doi_Thu.Presenter.Do(ClientMSG.ThemBaiVaoMo, temp);
                Mo_Doi_Thu.Add(temp);
        }
        //-----------------------Move Card----------------------------------//
        private void ProcessFromServer_API_MOVECARD(object[] data)
        {
            int id = (int)data[1];
            Zone from = (Zone)data[2];
            Zone to = (Zone)data[3];
            if(from == Zone.DECK && to == Zone.HAND)
            {
                YBaseCard new_card = this.converter.GetCard((int)data[0]);
                new_card.ID = id;
                this.Nguoi_Choi.Presenter.Do(ClientMSG.RutBai,new_card);
            }
            else if (from== Zone.TABLE && to == Zone.HAND)
            {
                YBaseCard card = this.Nguoi_Choi.FindOnTable(id);
                this.Nguoi_Choi.Presenter.Do(ClientMSG.RutBai, card);
                this.TableGame.Presenter.Do(ClientMSG.Api_MoveToHand, id);
            }
        }
        private void ProcessFromServer_API_MOVECARD_DOITHU(object[] data)
        {
          
            Zone from = (Zone)data[0];
            Zone to = (Zone)data[1];
           
            if (from == Zone.DECK && to == Zone.HAND)
            {
                this.Doi_Thu.Presenter.Do(ClientMSG.ThemBaiDoiThuTay, data);
            }
            else if (from == Zone.TABLE && to == Zone.HAND)
            {
                int id = (int)data[3];
                YBaseCard card = this.Doi_Thu.FindOnTable(id);
                this.Doi_Thu.Presenter.Do(ClientMSG.ThemBaiDoiThuTay, data);
                this.TableGame.Presenter.Do(ClientMSG.Api_MoveToHand_DoiThu, id);
            }
        }
        //------------------------Wait Active-------------------------
        private void ProcessFromServer_CARD_WAITING_ACTIVE_BEGIN(object[] data)
        {
            this.Doi_Thu.Presenter.Do(ClientMSG.Block_Wait_Active_Begin);
        }
        private void ProcessFromServer_CARD_WAITING_ACTIVE_END(object[] data)
        {
            this.Doi_Thu.Presenter.Do(ClientMSG.Block_Wait_Active_End);
        }
        // -----------------------Request----------------------  
        private void ProcessFromServer_REQUEST_ASK(object[] data)
        {
            RequestAPI.ReqestItem item = new RequestAPI.ReqestItem();
            item.ID = (int)data[0];
            item.Type = Common.YMSG.REQUEST_ASK;
            item.Res_Type = Common.YMSG.RESPONE_ASK;
            item.AditionData = data[1];
            RequestAPI.Push(item);
            this.TableGame.Presenter.Do(ClientMSG.Request, data);
            //this.SendMessageToServer(item.Res_Type, item.ID, 1);
        }
        private void ProcessFromServer_REQUEST_CHONBAI_DOITHU_BAN(object[] data)
        {
            RequestAPI.ReqestItem item = new RequestAPI.ReqestItem();
            item.ID = (int)data[0];
            item.Number = (int)data[1];
            item.Type = Common.YMSG.REQUEST_CHONBAI_DOITHU_BAN;
            item.Res_Type = Common.YMSG.RESPONE_CHONBAI_DOITHU_BAN;
            item.Card_Type = (YType)data[2];
            RequestAPI.Push(item);
            this.TableGame.Presenter.Do(ClientMSG.Request, data);
        }
        private void ProcessFromServer_REQUEST_CHONBAI_NGUOICHOI_BAN(object[] data)
        {
            RequestAPI.ReqestItem item = new RequestAPI.ReqestItem();
            item.ID = (int)data[0];
            item.Number = (int)data[1];
            item.Type = Common.YMSG.REQUEST_CHONBAI_NGUOICHOI_BAN;
            item.Res_Type = Common.YMSG.RESPONE_CHONBAI_NGUOICHOI_BAN;
            item.Card_Type = (YType)data[2];
            RequestAPI.Push(item);
            this.TableGame.Presenter.Do(ClientMSG.Request, data);
           
                
        }
        private void ProcessFromServer_REQUEST_CHONBAI_NGUOICHOI_TAY(object[] data)
        {
            RequestAPI.ReqestItem item = new RequestAPI.ReqestItem();
            item.ID = (int)data[0];
            item.Number = (int)data[1];
            item.Type = Common.YMSG.REQUEST_CHONBAI_NGUOICHOI_TAY;
            item.Res_Type = Common.YMSG.RESPONE_CHONBAI_NGUOICHOI_TAY;
            item.Card_Type = (YType)data[2];
            RequestAPI.Push(item);
            this.Nguoi_Choi.Presenter.Do(ClientMSG.Request, data);
            
        }
        private void ProcessFromServer_REQUEST_CHONBAI_DOITHU_TAY(object[] data)
        {
            RequestAPI.ReqestItem item = new RequestAPI.ReqestItem();
            item.ID = (int)data[0];
            item.Number = (int)data[1];
            item.Type = Common.YMSG.REQUEST_CHONBAI_DOITHU_TAY;
            item.Res_Type = Common.YMSG.RESPONE_CHONBAI_DOITHU_TAY;
            item.Card_Type = (YType)data[2];
            RequestAPI.Push(item);
            this.Doi_Thu.Presenter.Do(ClientMSG.Request, data);
        }
        private void ProcessFromServer_REQUEST_CHONBAI_TRENBAN(object[] data)
        {
            RequestAPI.ReqestItem item = new RequestAPI.ReqestItem();
            item.ID = (int)data[0];
            item.Number = (int)data[1];
            item.Type = Common.YMSG.REQUEST_CHONBAI_TRENBAN;
            item.Res_Type = Common.YMSG.RESPONE_CHONBAI_TRENBAN;
            item.Card_Type = (YType)data[2];
            RequestAPI.Push(item);
            this.TableGame.Presenter.Do(ClientMSG.Request, data);
        }
        private void ProcessFromServer_REQUEST_CHONBAI_DANHSACH(object[] data)
        {
            RequestAPI.ReqestItem item = new RequestAPI.ReqestItem();
            item.ID = (int)data[0];
            item.Number = (int)data[1];
            item.Type = Common.YMSG.RESPONE_CHONBAI_DANHSACH;
            item.Res_Type = Common.YMSG.RESPONE_CHONBAI_DANHSACH;
            item.AditionData = data[2];
            RequestAPI.Push(item);
            this.TableGame.Presenter.Do(ClientMSG.Request, data);
        }
        //---------------------------------Active----------------------------
        private void ProcessFromServer_CARD_LIST_CANEXCUTE(object[] data)
        {
            this.TableGame.Presenter.Do(ClientMSG.ShowListCanExcute, data);
        }
    }
}
